<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
         <!--<el-button type="primary" class="myBgGreen" @click="add">数据同步</el-button>-->
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">     
    	    <el-col :span="5">
        <template>
          <el-cascader
          placeholder="全部项目/小区"
          :options="regionOptions"
          filterable
          change-on-select
          v-model="regionOptSelected"
          ></el-cascader>
        </template>
      </el-col>
       <el-col :span="3">
        <el-date-picker
          v-model="startTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="开始时间">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <el-date-picker
          v-model="endTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <template>
          <el-select 
            v-model="Results"
            clearable
            placeholder="识别结果">
            <el-option
              v-for="item in ResultsList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="5">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="3">
        <el-button type="primary" class="myBgGreen" @click="fuzzySearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          ref="multipleTable"
          :data="list"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            type="selection"
            prop=""
             label="序号"
            width="55">
          </el-table-column>
          <el-table-column
            prop="user_name"
            label="访客姓名"
            >
          </el-table-column>
          <el-table-column
            prop="sysc_time"
            label="识别时间"
            >             
          </el-table-column>
          <el-table-column            
            label="进出类型"
            >
            <template scope="scope">
              <span v-if="scope.row.type==0">进</span>
              <span  v-else>出</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="device_name"
            label="设备名称"
            >            
          </el-table-column>
          
            <el-table-column
            
            label="通行方式"
            >  
            <template scope="scope">
              <span v-if="scope.row.identify==0">人脸识别</span>
              <span  v-else>IC卡识别</span>
            </template>           
          </el-table-column>                         
           <el-table-column            
            label="识别结果"
            >   
             <template scope="scope">
              <span v-if="scope.row.result_type==0">成功</span>
              <span  v-else>失败</span>
            </template> 
          </el-table-column>
          <el-table-column
            label="操作"
            width="100">
            <template scope="scope">
            	<el-button @click="getDetail(scope.row.id)" class="look" type="text" size="small">查看</el-button>                                           
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
</style>

<script>
  import { getManThroughList } from '@/api/entrance_guard';
  import { getRegion } from '@/utils/localstorage';
  import { extractAreaIds } from '@/utils/misc';
  
  export default {
    data(){
      return{  
        title:"业主通行记录",    
        list:[],  

        page_size: null, //每页显示多少条
        page_num: null, //当前页码
        total:null, //总条数  

        selectedLd:"-1",
        ldList:[],
        building_id:-1,
        lookObj:{},
      
        id:null,
        index:null,
        idArr:[],
        area_id: -1,
        pages:1000,
        loading:false,
        multipleSelection: [],
        
         // 小区选择
        regionOptions: [],
        regionOptSelected: [],
        
        Results:"",
        ResultsList:[{value:0,label:"成功"},{value:1,label:"失败"}],
        
        startTime:"",
        endTime:"",
        kw:"",
        deleteStatus1:"",
        deleteStatus1List:[]
      }
    },
    
     created() {
        document.title=this.title;
      	this.regionOptions = getRegion();
        this.regionOptSelected.push(this.regionOptions[0].value,this.regionOptions[0].children[0].value,this.regionOptions[0].children[0].children[0].value);
      
        this.fetchList();                                                                                                                                                                                    
    },
    computed: {
      areaIds() {
        return extractAreaIds(this.regionOptSelected, this.regionOptions);
      }
    },

    filters: {
       cardType: function(value) {
        let src = '';
        switch (value) {
          case 1:
            src = '卡片';
          break;
          case 2:
            src = '身份证';
          break;
          case 3:
            src = '银行卡';
          break;
        }
        return src;    
      }           
  },

    methods:{
       fetchList() {
        let vm = this;
        const params = {
          page_size: this.page_size,
          area_id:vm.areaIds,
          kw: this.kw,
          result_type:this.Results,
          start_date:this.startTime,
          end_date:this.endTime,
          page_num: this.page_num
        }
        vm.loading = true;
        getManThroughList(params)
        .then(response => {
          let res = response.data;
          vm.list = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;
          
          vm.loading = false;
        })
        .catch(error => {
          vm.loading = false;
        });
      },
      
      fuzzySearch() {
         this.fetchList();
      },
      
      handleSizeChange(val) {
        this.page_size = val;
        this.fetchList();
      },
      
      handleCurrentChange(val) {
        let pageNum=window.localStorage.getItem("pageNum");
        if(pageNum){
          this.page_num = Number(pageNum);
          window.localStorage.removeItem("pageNum");
        }else{
          this.page_num = val;
        }
        this.fetchList();
      },
      
      add:function(){

      },
      
     getDetail:function(id){
        this.$router.push({
          path:'/manPassageRecordComonents',
          query: {type: 'info', id: id, pageNum: this.page_num}
        })
      },

     //----页码---
      handleSelectionChange(val) {
        this.multipleSelection = val;
        if(val.length!=0){
          for(var i = 0;i<val.length;i++){
            this.idArr.push(val[i].area_id)
          }
        }else{
          this.idArr = [];
        }
              
      },
       indexMethod(index) {
          return (this.page_num-1)*this.page_size + index + 1
      }
     
    }

  }


</script>



